import { UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth } from '@nestjs/swagger';
import { CrudOptions } from '@nestjsx/crud';
import { HandleStatus } from 'libs/db/entity/enum/handle-status.enum';
import { Villager } from 'libs/db/entity/villager.entity';
import { LoggerInfo, moduleLoggerInfo } from '../_decorator/logger-info';

export const VillagerCrudOps: CrudOptions = {
  model: {
    type: Villager,
  },
  query: {
     
    join: {
      village: {
        exclude: ['createdAt', 'updatedAt', 'deleteAt'],
      },
      "village.town": {
        // alias: "town",
        exclude:  ["updatedAt", "deleteAt"],
      },
      "town.area": {
        exclude:  ["updatedAt", "deleteAt"],
      },
      group: {
        exclude: ['createdAt', 'updatedAt', 'deleteAt'],
      },
    },
    exclude: ['updatedAt', 'deleteAt', 'password'],
  },
  routes: {
    only: ['getOneBase', 'getManyBase', 'replaceOneBase', 'updateOneBase'],
    exclude: ['deleteOneBase', 'createManyBase', 'createOneBase'],
    getManyBase: {
      interceptors: [],
      decorators: [
        UseGuards(AuthGuard('jwt-web')),
        ApiBearerAuth(),
        LoggerInfo(
          new moduleLoggerInfo ('村民用户查询',HandleStatus.LOG)
        )
      ],
    },
    getOneBase: {
      interceptors: [],
      decorators: [
        UseGuards(AuthGuard('jwt-web')),
        ApiBearerAuth(),
        LoggerInfo(
          new moduleLoggerInfo ('单个村民用户查询', HandleStatus.LOG)
        ),
      ],
    },
    createOneBase: {
      interceptors: [],
      decorators: [
        
        LoggerInfo(
          new moduleLoggerInfo ('新增村民用户', HandleStatus.INFO)
        ),
      ],
      returnShallow: true,
    },
    createManyBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('村民信息上传', HandleStatus.DATA)
        ),
      ],
    },
    replaceOneBase: {
      interceptors: [],
      decorators: [
        UseGuards(AuthGuard('jwt-web')),
        ApiBearerAuth(),
        LoggerInfo(
          new moduleLoggerInfo ('修改村民信息', HandleStatus.WARN)
        ),
      ],
      allowParamsOverride: true,
      returnShallow: true,
    },
    updateOneBase: {
      interceptors: [],
      decorators: [
        UseGuards(AuthGuard('jwt-web')),
        ApiBearerAuth(),
        LoggerInfo(
          new moduleLoggerInfo ('修改村民信息', HandleStatus.WARN)
        ),
      ],
      allowParamsOverride: true,
      returnShallow: true,
    },
    deleteOneBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('删除村民信息', HandleStatus.ERROR)
        ),
      ],
      returnDeleted: true,
    },
  },
  dto: {
    create: Villager,
    replace: Villager,
  },
  serialize: {
    getMany: Villager,
    get: Villager,
    create: Villager,
    createMany: Villager,
    update: Villager,
    replace: Villager,
    delete: Villager,
  },
};
